from Footle_Parser import *
import sys
sys.path.append(sys.path[0] + "/../LLVM")
from llvmhelper import *
from StaticPass import *

class runTestFile:
	def __init__(self):
		if(len(sys.argv) > 1):
			in_file = open(sys.argv[1],"r")
		else:
			in_file = open("test3.footle", "r")
		self.code = in_file.read()
		self.parser = parserClass(self.code)
		self.helper = llvmHelper()
		in_file.close()


	
	def run(self):
		generatedAST =	self.parser.parse()
		print "Generated AST:\n" + str(generatedAST)
		print "\n ----------------------------------------------------\n"
		staticAST = StaticPass(generatedAST, self.helper)
		staticAST.run()
		#print "Scope list: " 
		#self.helper.displayScope()
		#self.helper.printFunctions()
		#self.helper.printMemberData()
		
		#print "\n" + self.helper.getDispatch()
		
		interp = interpreter(generatedAST)
		print "\nInterpreted answer: ",interp.execute()
	
	def getErrorStr(self):
		return "Prog: " + str(self.prog) + "\nExpected: " + str(self.aststr) + "\nFound: "  + str(self.generatedASTstr) + "\n"
		
if __name__ == '__main__':
	test = runTestFile()
	test.run()
